extends PropertyFindSetter


class_name AttributeSetter


## 属性名称
@export var attr_name: String = ""
## 操作符
@export_enum("=:0", "+=:1", "-=:2", "*=:3", "/=:4", "%=:5") var operation: int = 0
## 操作数
@export var value: int = 0


func __calc_value(op: int, src_v: int, op_v: int) -> int:
    match op:
        0: return op_v
        1: return src_v + op_v
        2: return src_v - op_v
        3: return src_v * op_v
        4: return int(src_v / op_v)
        5: return src_v % op_v
    # 无法匹配, 不做修改
    return src_v

func __get_wrapper_and_property() -> bool:
    var character: ICharacterComponent = get_wrapper()
    if not character:
        return false
    var attr: Attribute = character.get_attribute(attr_name)
    if attr:
        cached_w = attr
        cached_p = property
        return true
    return false

func __get_update_value(w: Object, p: String) -> Variant:
    if operation > 0:
        return __calc_value(operation, w.get(p), value)
    return value
